Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve channel map operations in respect of thread-safety #655

Merged
merged 3 commits into from
Mar 3, 2021

Conversation

QuintinWillison
Copy link
Contributor

Fixes #649.

@vzhikserg
Copy link
Contributor

@QuintinWillison could you please remove unused imports?

@QuintinWillison
Copy link
Contributor Author

Thanks, @vzhikserg ... that was rather sloppy of me! 🤦
Fixing that now. Commit to follow.

// Hence there's the slight inefficiency of creating newChannel when it may not be
// needed because there is an existingChannel.
final Channel newChannel = new Channel(AblyRealtime.this, channelName, channelOptions);
final Channel existingChannel = map.putIfAbsent(channelName, newChannel);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your point. That is the method that this refactor is pretty much focussed on avoiding the use of. I've replaced two calls (one to get, followed by a subsequent conditional call to put, with a single call to atomic putIfAbsent as backed by the concurrent hash map).

Perhaps you need to re-read the issue to see what we're aiming to solve here. 🤔

Copy link
Collaborator

@sacOO7 sacOO7 Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I was looking at the comment slight inefficiency of creating newChannel, if we use map.get(channelName), we can avoid it. I feel it's a tradeoff, in most cases, the client will try to get an existing channel rather than creating a new one.

Copy link
Member

@paddybyers paddybyers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@QuintinWillison QuintinWillison merged commit 27a5961 into main Mar 3, 2021
@QuintinWillison QuintinWillison deleted the feature/issue-649 branch March 3, 2021 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

AblyBase.InternalChannels is not thread-safe
4 participants